#ifndef CONNETWORK_H
#define CONNETWORK_H

#include <iostream>
#include <cstring>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <thread>
#include <string>
#include "logger.h"

using namespace std;

namespace connetwork{

class work
{

#define BUFFER_SIZE 1024

public:


    work():sever_port(8888), sever_fd(-1),client_len(sizeof(client_address)){
        logermanager = new loger::Logger;
        logermanager = &loger::LoggerManager::getLogger("Network communication logger_");
        logermanager->setLogLevel(loger::LogLevel::INFO);
    }
    ~work(){
        if (sever_fd != -1) {
            close(sever_fd);
        }
        // if(logermanager != nullptr)
        // {
        //     delete logermanager;
        // }
    };
    void createSocket();
    void bindSocket();
    void listenForConnections();

    void receiveMessages(int client_socket);
    void sendMessages(int client_socket);
    int sever_port;
    int sever_fd;

    loger::Logger *logermanager;
private:
    struct sockaddr_in client_address;
    socklen_t client_len;
};

class TCPServer :public thread
{
public:
    TCPServer();
    ~TCPServer();
    void run() ;
private:
    work *workfd;
};

}

#endif 